<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import = "com.db4o.servlet.Db4oServlet" %>
<%@page import = "facades.*" %>
<%@page import = "auser.*" %>
<%@page import = "com.db4o.query.*" %>
<% SessionFacade sfacade = new SessionFacade(session); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet"  href="<%=request.getContextPath()%>/css/display.css" type="text/css" media="screen" />
<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script src="<%=request.getContextPath()%>/js/form.js"></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/js/input01.js'></script>
<title>Gestione Auser - Ricerca Accompagnamenti per modifica</title>
</head>
<body>
	
	<% 
	
		java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(new java.util.Date());	
		int annoAccompagnamento= cal.get(java.util.Calendar.YEAR);
		int meseAccompagnamento= cal.get(java.util.Calendar.MONTH)+1;
		
		pageContext.setAttribute("yearToday",annoAccompagnamento);
		pageContext.setAttribute("monthToday",meseAccompagnamento);
	%>	
	 
	<c:set var="curAnno" value="${param.anno}" />	 	 	
	<c:if test="${empty param.anno}">
		<c:set var="curAnno" value="${yearToday}" />
	</c:if>	 	 		 
	
	<c:set var="curMese" value="${param.mese}" />
	<c:if test="${empty param.mese}">
		<c:set var="curMese" value="${monthToday}" />
	</c:if>	  
	
	 <form method="post" action="searchedit.jsp" name="frmsearch" >
		<h1>Ricerca Accompagnamento per modifica</h1> 
		<fieldset>
			<legend>Dati per ricerca</legend> 
	 		<label for='anno'>Anno Accomp.</label><input type="text" class="Integer" name="anno" id="anno" size="4" value="${curAnno}" /><br/>
	 		<label for='mese'>Mese Accomp.</label>
	 			<select name="mese" id="mese">
	 				<option value="0" ${curMese=='0'?"selected":""}>- Tutto l'anno - 
	 				<option value="1" ${curMese==1?"selected":""}>Gen.
	 				<option value="2" ${curMese==2?"selected":""}>Feb.
	 				<option value="3" ${curMese==3?"selected":""}>Mar.
	 				<option value="4" ${curMese==4?"selected":""}>Apr.
	 				<option value="5" ${curMese==5?"selected":""}>Mag.
	 				<option value="6" ${curMese==6?"selected":""}>Giu.
	 				<option value="7" ${curMese==7?"selected":""}>Lug.
	 				<option value="8" ${curMese==8?"selected":""}>Ago.
	 				<option value="9" ${curMese==9?"selected":""}>Set.
	 				<option value="10" ${curMese==10?"selected":""}>Ott.
	 				<option value="11" ${curMese==11?"selected":""}>Nov.
	 				<option value="12" ${curMese==12?"selected":""}>Dic.
	 			</select><br>
	 		
	 		<label for='motivo'>Motivo</label>	
	 		<select id="motivo" name="motivo">
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("From auser.MotiviAccompagnamento m order by descrizione") %>" var="obj"> 
	 					<option value="${obj.descrizione}" ${obj.descrizione==param.motivo?"selected":"" } >${obj.descrizione}</option>
					</c:forEach>
	 			</select><br>
	 		
	 		<label for='disabile'>Disabile/Anziano</label><input type="text" name="disabile" id="disabile" size="45" value="${param.disabile}" /><br/>
	 		<div class='howtomsg'>Cognome disabile (Attenzione alle Maiuscole)</div>
	 		
	 		<!--   label for='accompagnatore'>Accompagnatore</label><input type="text" name="accompagnatore" id="accompagnatore" size="45" value="${param.accompagnatore}" /><br/>
	 		<label for='autista'>Autista</label><input type="text" name="autista" id="autista" size="45" value="${param.autista}" /><br/>
	 		<br/ -->
	 		<br>
	 		<input type="hidden" name="sent" id="sent" value="" />
	 		<input onclick="$('#sent').val('OK')" class='button' type="submit" value='Cerca' id='btnSave' name='btnSave' /> 
			<input  class='button' type='button' value='Chiudi' id='btnClose' onclick='document.location="<%=request.getContextPath()%>/app/start/index.jsp"'>
	 	</fieldset>
	 	 
	 	<c:if test="${(!empty param.motivo || !empty curAnno || !empty curMese) && !empty param.sent }">
			 
			<% 
				StringBuffer where = new StringBuffer(" o.annoAccompagnamento>0 ");
			
				if(request.getParameter("anno")!=null && !request.getParameter("anno").equals("")) 
					where.append(" and o.annoAccompagnamento=" + request.getParameter("anno")) ;  
				
				if(request.getParameter("mese")!=null && !request.getParameter("mese").equals("0") && !request.getParameter("mese").equals("")) 
					where.append(" and o.meseAnnoAccompagnamento='" + request.getParameter("mese")+request.getParameter("anno") +"'") ;    
				
				if(request.getParameter("motivo")!=null && !request.getParameter("motivo").equals("")) 
					where.append(" and o.motivo.descrizione = '" + request.getParameter("motivo") + "'")  ;    
				 
				if(request.getParameter("disabile")!=null && !request.getParameter("disabile").equals("")) 
					where.append(" and o.disabile.cognome = '" + request.getParameter("disabile") + "'")  ;    
				
				
				java.util.List result = sfacade.querySql("Accompagnamento",where.toString(),"dataAccompagnamento",true);
			
			%>
			
			 
		 	<div class='howtomsg'>Fai un click sulla data Accompagnamento per modificarlo</div>
		 	
		 	<fieldset class='searchResult'>
				<legend>Risultati</legend> 
				<table border="1" cellpadding="4">
				
					<%  int co=0;  %>
					<tr><th>Data<th>Disabile/Anziano<th>Motivo<th>Accompagnatore<th>Autista
			 		<c:forEach items="<%=result%>" var="obj" varStatus="status">
						<tr>
							<td><a href='loader.jsp?id=<%=sfacade.getID("obj",pageContext) %>'><b>- <fmt:formatDate pattern="dd/MM/yyyy" value='${obj.dataAccompagnamento}'/></b></a> &nbsp;
							<td> ${obj.disabile.cognome } ${obj.disabile.nome }&nbsp;
							<td> ${obj.motivo.descrizione }&nbsp;
							<td> ${obj.accompagnatore.cognome } ${obj.accompagnatore.nome }&nbsp;
							<td> ${obj.autista.cognome } ${obj.autista.nome } &nbsp; 
						<% co++; %>
					</c:forEach>
					<%  if(co==0) { %>
						<tr><td colspan="5">Nessun Accompagnamento trovato 
					<%  } // if co==0 %>
				 
				</table>
		 	</fieldset>
	 	</c:if>
	 </form>

	
</body>
</html>